package installer;

import java.io.IOException;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

public class InstallJFS {
	private static JdbcTemplate jdbcTemplate;

	@BeforeClass
	public static void before() {
		ApplicationContext ctx = new ClassPathXmlApplicationContext(
				"config/context/applicationContext.xml");
		jdbcTemplate = (JdbcTemplate) ctx.getBean("jdbcTemplate");
	}

	@Test
	public void install() {
		try {
			String sql = SQLGetter.get("installer//InstallJFSDirectory.sql");
			jdbcTemplate.update(sql);
			sql = SQLGetter.get("installer//InstallJFSFile.sql");
			jdbcTemplate.update(sql);
			sql = SQLGetter.get("installer//InstallAdministrator.sql");
			jdbcTemplate.update(sql);
			sql = SQLGetter.get("installer//InstallJFSNode.sql");
			jdbcTemplate.update(sql);
			sql = SQLGetter.get("installer//InstallStorage.sql");
			jdbcTemplate.update(sql);
			sql = SQLGetter.get("installer//InitJFSDirectory.sql");
			jdbcTemplate.update(sql);
			sql = SQLGetter.get("installer//InitAdministrator.sql");
			jdbcTemplate.update(sql);
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
